package com.zrrd._01_servlet.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author WanJl
 * @version 1.0
 * @title RequestDemo01
 * @description 请求测试
 * @create 2024/1/13 9:45
 */
@WebServlet("/requestDemo01")
public class RequestDemo01 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //使用的是HttpServletRequest对象，获取的是请求数据(参数)
        String username = req.getParameter("username");

        //使用HttpServletResponse对象，设置响应的数据(响应内容)
        //设置响应头
        resp.setHeader("Content-Type","text/html; charset=utf-8");
        //设置响应内容
        resp.getWriter().write("<h1>"+username+"欢迎你！！！</h1>");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req,resp);
    }
}
